package com.lancoo.klgcourseware.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lancoo.klgcourseware.R;
import com.lancoo.klgcourseware.entity.bean.SpellCharacterBean;
import com.lancoo.klgcourseware.utils.KlgToolUtils;

import java.util.List;


/**
 * Created by pengmi on 2019/1/3.
 * Description:
 */

public class FastCharacterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;
    private List<SpellCharacterBean> spellCharacterBeans;
    private int showIndex=-1;
    private boolean isTraining;

    public FastCharacterAdapter(Context mContext, List<SpellCharacterBean> spellCharacterBeans) {
        this.mContext = mContext;
        this.spellCharacterBeans = spellCharacterBeans;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.klg_list_item_fast_character, viewGroup, false);
        SpellCharacterVh spellCharacterVh=new SpellCharacterVh(inflate);
        return spellCharacterVh;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        SpellCharacterVh spellCharacterVh= (SpellCharacterVh) viewHolder;
        spellCharacterVh.initData(spellCharacterBeans.get(i),i);
    }

    @Override
    public int getItemCount() {
        return spellCharacterBeans.size();
    }


    private class SpellCharacterVh extends RecyclerView.ViewHolder{
        public TextView tv_character;

        public SpellCharacterVh(@NonNull View itemView) {
            super(itemView);
            tv_character=itemView.findViewById(R.id.tv_character);
        }

        public void initData(SpellCharacterBean spellCharacterBean,int position){
            tv_character.setText(spellCharacterBean.getCharacter());
            if(isTraining){
                tv_character.setTextColor(Color.parseColor(showIndex>0?"#004ce8":"#aae3f5"));
                tv_character.setTextSize(KlgToolUtils.isPad(mContext)?36:30);
            }else{
                tv_character.setTextColor(Color.parseColor("#b9b9b9"));
                tv_character.setTextSize(KlgToolUtils.isPad(mContext)?24:20);
            }
        }
    }

    public void changeRepeat(int showIndex){
        this.showIndex=showIndex;
        notifyDataSetChanged();
    }

    public void setTrainModel(boolean isTraining){
        this.isTraining=isTraining;
        notifyDataSetChanged();
    }

}
